package com.zretc.support.dao;

import com.zretc.support.entity.Question;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;


import java.io.Serializable;
import java.util.Date;
import java.util.List;

public interface QuestionDao extends JpaRepository<Question, Long>, JpaSpecificationExecutor<Question>,
        Serializable {

    List<Question> findByQuestionTitleContaining(String questionTitle);

    @Query(value = "select q " +
            "from Question q inner join User u " +
            "on q.user.userId = u.userId where q.questionTitle like %?1% " +
            "and q.questionContent like %?2% " +
            "and q.questionDate between ?3 and ?4")
    Page<Question> getQuestionByLAP(String questionTitle, String questionContent, Date startTime, Date endTime, Pageable pageable);

    Question findQuestionByQuestionId(long questionId);

    /**
     * 查询问题标题倒叙
     * @param pageable
     * @return
     */
    @Query(value = "select q from Question q order by q.questionDate desc ")
    Page<Question> getQuestionTitleList(Pageable pageable);


}
